<?
/**
 * Applet functions
 */
(basename($_SERVER['PHP_SELF']) == basename(__FILE__)) && die('Access Denied');

/**
 * Generate data and load list template when viewing audit log
 * @return void
 */
function getPageLog() {
	// requirements
	global $_APP;
	requireWebApp();

	// obtain object and set list properties
	$dbo = getDbo('Log');
	if ($_APP->html->downloadRequested()) {
		$props = getListDownloadProperties($dbo);
		} else {
		$props = array('LogDate', 'LogApp', 'LogUser', 'LogText');
		}
	$_APP->html->setPropertiesList($props);

	// search properties
	foreach($props as &$prop) {
		$_APP->html->addSearchProperty($prop);
		}

	// Default search property and order
	$_APP->html->setSearchPropertyDefault('LogText');
	$_APP->html->setSearchOrderDefault('LogDate DESC');

	// Reset search
	$dbo->searchReset();

	// Apply any user searches
	$_APP->html->setUserInput($dbo);

	// Do the query
	$_APP->html->doQueryList($dbo);

	// Take care of download requests
	if ($_APP->html->downloadRequested()) {
		$h = array();
		// first line contains field names
		$h[] = '"' . implode('","', $props) . '"';
		foreach($_APP->html->searchResults as &$row) {
			$r = str_replace('"', '""', $row);
			$h[] = '"' . implode('","', $r) . '"';
			}
		$txt = implode("\r\n",$h) . "\r\n";
		unset($h);
		die($_APP->html->uploadContent($txt, 'audit-log.csv'));
		}

	// set up the html template
	$_APP->html->setVar('list', $dbo);
	die($_APP->html->getTemplate('list.php'));
	}

?>
